﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace MMK.Paket_Tracker.GUI.UserControls
{
    /// <summary>
    /// Interaction logic for Entry.xaml
    /// </summary>
    public partial class Entry : UserControl
    {
        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="Entry"/> class.
        /// </summary>
        public Entry()
        {
            InitializeComponent();
        }
        #endregion


        #region public methods
        /// <summary>
        /// Gets or sets the width of the entry label in the UserControl.
        /// </summary>
        /// <value>The width of the entry label in the UserControl.</value>
        public Double EntryLabelWidth
        {
            get { return (Double)GetValue(EntryLabelWidthProperty); }
            set { SetValue(EntryLabelWidthProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for EntryLabelWidth.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty EntryLabelWidthProperty =
            DependencyProperty.Register("EntryLabelWidth", typeof(Double), typeof(Entry), new UIPropertyMetadata(OnEntryLabelWidthChanged));

        /// <summary>
        /// Gets or sets the width of the entry field.
        /// </summary>
        /// <value>
        /// The width of the entry field.
        /// </value>
        public Double EntryFieldWidth
        {
            get { return (Double)GetValue(EntryFieldWidthProperty); }
            set { SetValue(EntryFieldWidthProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for EntryFieldWidth.  This enables animation, styling, binding, etc... 
        /// </summary>
        public static readonly DependencyProperty EntryFieldWidthProperty =
            DependencyProperty.Register("EntryFieldWidth", typeof(Double), typeof(Entry), new UIPropertyMetadata(OnEntryFieldWidthChanged));



        /// <summary>
        /// Gets or sets the content of the entry label.
        /// </summary>
        /// <value>
        /// The content of the entry label.
        /// </value>
        public String EntryLabelContent
        {
            get { return (String)GetValue(EntryLabelContentProperty); }
            set { SetValue(EntryLabelContentProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for EntryLabelContent.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty EntryLabelContentProperty =
            DependencyProperty.Register("EntryLabelContent", typeof(String), typeof(Entry), new UIPropertyMetadata(OnEntryLabelContentChanged));



        /// <summary>
        /// Gets or sets the max length of the entry field.
        /// </summary>
        /// <value>The length of the entry field.</value>
        public Int32 EntryFieldMaxLength
        {
            get { return (Int32)GetValue(EntryFieldMaxLengthProperty); }
            set { SetValue(EntryFieldMaxLengthProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for EntryFieldMaxLength.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty EntryFieldMaxLengthProperty =
            DependencyProperty.Register("EntryFieldMaxLength", typeof(Int32), typeof(Entry), new UIPropertyMetadata(OnEntryFieldMaxLengthChanged));




        /// <summary>
        /// Gets or sets the length of the entry field min.
        /// </summary>
        /// <value>The length of the entry field min.</value>
        public Int32 EntryFieldMinLength
        {
            get { return (Int32)GetValue(EntryFieldMinLengthProperty); }
            set { SetValue(EntryFieldMinLengthProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for EntryFieldMinLength.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty EntryFieldMinLengthProperty =
            DependencyProperty.Register("EntryFieldMinLength", typeof(Int32), typeof(Entry), new UIPropertyMetadata(0));

        

        /// <summary>
        /// Gets or sets the entry field text.
        /// </summary>
        /// <value>The entry field text.</value>
        public String EntryFieldText
        {
            get { return (String)GetValue(EntryFieldTextProperty); }
            set { SetValue(EntryFieldTextProperty, value); }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for EntryFieldText.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty EntryFieldTextProperty =
            DependencyProperty.Register("EntryFieldText", typeof(String), typeof(Entry), new UIPropertyMetadata(OnEntryFieldTextChanged));

        
        #endregion


        #region private methods
        private static void OnEntryLabelWidthChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Entry entry = (Entry)sender;
            entry.EntryLabel.Width = (Double)e.NewValue;
        }

        private static void OnEntryFieldWidthChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Entry entry = (Entry)sender;
            entry.EntryBox.Width = (Double)e.NewValue;
        }

        private static void OnEntryLabelContentChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Entry entry = (Entry)sender;
            entry.EntryLabel.Content = (String)e.NewValue;
        }

        private static void OnEntryFieldMaxLengthChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Entry entry = (Entry)sender;
            entry.EntryBox.MaxLength = (Int32)e.NewValue;
        }

        private static void OnEntryFieldTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Entry entry = (Entry)sender;
            entry.EntryBox.Text = (String)e.NewValue;
        }

        #endregion

    }
}
